﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ExcelReport
{
    public class Functional
    {
        public string UUT { get; set; }
        public string Date { get; set; }
        public string Time { get; set; }
        public string CarrierNo { get; set; }
        public string Result { get; set; }
        public string Turn1 { get; set; }
        public string Turn2 { get; set; }
        public string Turn3 { get; set; }
        public string Turn4 { get; set; }
        public string LX1 { get; set; }
        public string LX2 { get; set; }
        public string LX3 { get; set; }
        public string CX1 { get; set; }
        public string DCR1 { get; set; }
        public string DCR2 { get; set; }
        public string DCR3 { get; set; }
        public string DCR4 { get; set; }
        public string DCR5 { get; set; }
        public string DCR6 { get; set; }
    }
    public class FuntionalReport
    {
        #region 获取日期范围内的所有数据
        /// <summary>
        /// Obtain the test data from test log according to the test log
        /// </summary>
        /// <param name="BeginDate"></param>
        /// <param name="EndDate"></param>
        /// <returns></returns>
        public List<Functional> getFunctionals(string BeginDate, string EndDate)
        {
            string InitialDir = "D:\\Logs\\";
            List<Functional> Functionals = new List<Functional>();
            List<string> fileNames = new List<string>();
            DateTime Date = DateTime.Parse(BeginDate);
            while (Date <= DateTime.Parse(EndDate))
            {
                string FileName = string.Format("{0}\\{1}\\FuctionalTest_{2}.csv"
                   , InitialDir
                   , Date.ToString("yyyy-MM-dd")
                   , Date.ToString("yyyy-MM-dd"));
                if (File.Exists(FileName))
                {
                    fileNames.Add(FileName);
                }
                Date = Date.AddDays(1);
            }
            foreach (var fileName in fileNames)
            {
                try
                {
                    StreamReader sr = new StreamReader(fileName);
                    string Header = sr.ReadLine();
                    while (!sr.EndOfStream)
                    {
                        string[] rows = sr.ReadLine().Split(',');
                        Functional fn = new Functional();
                        fn.UUT = rows[0];
                        fn.Date = rows[1];
                        fn.Time = rows[2];
                        fn.CarrierNo = rows[3];
                        fn.Result = rows[4];
                        fn.Turn1 = rows[5];
                        fn.Turn2 = rows[6];
                        fn.Turn3 = rows[7];
                        fn.Turn4 = rows[8];
                        fn.LX1 = rows[9];
                        fn.LX2 = rows[10];
                        fn.LX3 = rows[11];
                        fn.CX1 = rows[12];
                        fn.DCR1 = rows[13];
                        fn.DCR2 = rows[14];
                        fn.DCR3 = rows[15];
                        fn.DCR4 = rows[16];
                        fn.DCR5 = rows[17];
                        fn.DCR6 = rows[18];
                        Functionals.Add(fn);
                    }

                }
                catch
                {
                    ;
                }

            }
            return Functionals;
        } 
        #endregion
    }
}
